package com.itheima.web;


import com.itheima.config.PatternProperties;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

@RestController
@RequestMapping("/user")
public class UserController {
    //注入userservice
    @Autowired
    private UserService userService;

    //注入配置类
    @Autowired
    private PatternProperties patternProperties;

    /**
     * 根据用户id查询用户信息
     *
     * @param userId 用户id
     * @return 返回用户对象
     */
    @GetMapping("{userId}")
    public User queryUserById(@PathVariable("userId") Long userId) {
        return userService.queryUserById(userId);
    }

    /**
     * 定义now方法
     */
    @GetMapping("now")
    public String now() {
        return LocalTime.now().format(DateTimeFormatter.ofPattern(patternProperties.getDateformat()));
    }

    /**
     * 文件配置读取
     */
    @GetMapping("prop")
    public PatternProperties prop() {
        return patternProperties;
    }

}
